package com.banmao.mall.service.client.impl;

import com.banmao.mall.mapper.BrandMapper;
import com.banmao.mall.model.bo.client.brand.BrandListBO;
import com.banmao.mall.model.vo.client.brand.BrandBaseVO;
import com.banmao.mall.model.vo.client.brand.BrandDetailVO;
import com.banmao.mall.model.vo.client.brand.BrandListVO;
import com.banmao.mall.service.client.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    BrandMapper brandMapper;

    @Override
    public BrandDetailVO brandDetail(Integer brandId) {

        BrandDetailVO brandDetailVO = brandMapper.selectDetailByID(brandId);

        return brandDetailVO;
    }

    @Override
    public BrandListVO brandList(BrandListBO brandListBO) {

        PageHelper.startPage(brandListBO.getPage(), brandListBO.getSize());

        List<BrandBaseVO> brandBaseVOList = brandMapper.selectAllBrand(brandListBO);

        PageInfo<BrandBaseVO> brandBaseVOPageInfo = new PageInfo<>(brandBaseVOList);

        int pages = brandBaseVOPageInfo.getPages();

        BrandListVO brandListVO = new BrandListVO();
        brandListVO.setTotalPages(pages);
        brandListVO.setBrandList(brandBaseVOList);

        return brandListVO;
    }
}
